﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace sy2_6
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
                    }

        private void btnConfirm_Click(object sender, EventArgs e)
        {
            int startYear, endYear;
            // 尝试将输入的起始年份和结束年份转换为整数
            if (int.TryParse(txtStartYear.Text, out startYear) && int.TryParse(txtEndYear.Text, out endYear))
            {
                txtLeapYears.Text = "";
                int count = 0;
                // 遍历指定年份范围，判断并显示闰年
                for (int year = startYear; year <= endYear; year++)
                {
                    // 闰年判断条件：能被 4 整除但不能被 100 整除，或者能被 400 整除
                    if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
                    {
                        txtLeapYears.Text += year + " ";
                        count++;
                        // 每 6 个闰年换一行，使显示更整齐
                        if (count % 6 == 0)
                        {
                            txtLeapYears.Text += Environment.NewLine;
                        }
                    }
                }
            }
            else
            {
                // 输入无法转换为整数时，弹出提示
                MessageBox.Show("请输入有效的年份！");
            }
        }
    }
}
